package com.qianyu.project.mapper.provider.gs;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * @author gs
 * @date create in 2021/1/31 10:20
 */
public class TenderPurchasePlanMapperProvider {

    public String selectPageList(IPage page, Map<String, String> params) {
        return new SQL() {
            {
                SELECT("tpp.*,pi.project_name,pi.id as project_id,pt.type_name as project_type");
                FROM("tender_purchase_plan tpp,project_info pi,project_type pt");
                WHERE("tpp.pro_id=pi.id and pt.type_id=pi.project_type");
                if (!ObjectUtils.isEmpty(params.get("projectName"))) {
                    WHERE("pi.project_name like '%${params.projectName}%'");
                }
                if (!ObjectUtils.isEmpty(params.get("planId"))) {
                    WHERE("tpp.id like '%${params.planId}%'");
                }
                if (!ObjectUtils.isEmpty(params.get("planEditor"))) {
                    WHERE("tpp.plan_editor like '%${params.planEditor}%'");
                }
                if (!ObjectUtils.isEmpty(params.get("approveStatus"))) {
                    WHERE("tpp.approve_status = #{params.approveStatus}");
                }
                if (!ObjectUtils.isEmpty(params.get("projectType"))) {
                    WHERE("pt.type_id=#{params.projectType}");
                }
                if (!ObjectUtils.isEmpty(params.get("status"))) {
                    WHERE("tpp.status=#{params.status}");
                }
            }
        }.toString();
    }
}
